const express = require('express')
const router = require('./src/routers/index')
const swig = require('swig')
const commonConfig = require('./config/commonConfig')
// 使用log4j记录日志
const log4j = require('./src/utils/logger')
const otherLog = log4j.getLogger()

const app = express()
// 解决跨域
app.use((req, res, next) => {
	res.header('Access-Control-Allow-Origin', '*')
	next()
})
// 添加数据解析
app.use(express.urlencoded({ extended: false }))
app.use(express.json())

//设置html渲染
app.set('views', './src/views/')
//设置html模板渲染引擎
app.engine('html', swig.renderFile)
//设置渲染引擎为html
app.set('view engine', 'html')

// 绑定接口
app.use('/', router)
app.listen(commonConfig.port, () => {
	console.log(commonConfig.baseUrl)
})
app.get('/', (req, res) => {
	res.render('index', {
		title: '首页'
	})
})
